<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
		<style>
			#div1,#div2{
				width: 100px;
				height: 100px;
				background: skyblue;
				line-height: 100px;
				text-align: center;
			}
			#div2{
				background: pink;
			}
		</style>
	<body>
		<div id="div1">单击</div>
		<div id="div2">双击</div>
		<script>
//			1.用代码实现一个8*8的棋盘；
			(function (){
				document.write('<table>');
				for (var i = 1; i <= 8; i++) {
					document.write('<tr>');
					for ( var j = 1; j <= 8; j++){
						if ( (i % 2 == 1 && j % 2 == 1) ||  (i % 2 == 0 && j % 2 == 0)){
							document.write('<td style="width:30px;height:30px;background: black;"></td>');
						}else{
							document.write('<td style="width:30px;height:30px;background: white;"></td>');
						}
					}
				
					document.write('</tr>');
				}
				document.write('</table>');
			})();
			
//			2.用代码实现以下功能：找出数组[2,5,3,4,5,9,4,5]中的重复的数字的重复次数（两个相同数字为一次）//indexOf(str) , lastIndexOf(str)
			(function (){
				var arr = [2,5,3,4,5,9,4,5];
				var arr2 = [];
				var timer = 0;
				for ( var i = 0; i < arr.length; i++ ) {
					if (arr2.indexOf(arr[i]) == -1){
						for ( var j = i + 1; j < arr.length; j++ ){
							if (arr[i] == arr[j]){
								timer++;
								arr2.push(arr[i]);
							}
						}
					}
				}
				
				console.log(timer);
			})();
//			冒泡排序 [7,5,10,2,1]
			(function () {
				var arr = [7,5,10,2,1];
				for ( var i = 0; i < arr.length; i++ ) {
					for ( var j = i + 1; j < arr.length; j++ ){
						if (arr[i] > arr[j]){
							TEMP = arr[i];
							arr[i] = arr[j];
							arr[j] = TEMP;
						}
					}
				}
				console.log(arr.toString());
			})();
//			用JavaScript实现鼠标三击功能
			(function(){
				var btn1 = document.getElementById('div1');
				var btn2 = document.getElementById('div2');
				var trigger = false;
				var t;
				btn1.addEventListener('mousedown', function () {
					console.log('单击');
				});
				btn2.addEventListener('mousedown', function () {
					if (trigger == true ){
						console.log('双击');
						clearTimeout(t);
						trigger = false;
					}else{
						trigger = true;
						t = setTimeout(function () {
							trigger = false;
						},200);
					}
				});
			})();
	</script>
	</body>
</html>
